GBML manual / Queues

queue_pop

Removes AND returns the item at the FRONT of target (the one pushed longest ago). If target is already empty, nothing is removed and a plain default value is returned instead (0/0.0/false/an empty string/`nothing`, depending on T) - target never crashes. Check queue_empty(target) first if you need to tell "the front was really this value" apart from "target was empty".

Syntax

queue_pop(target) -> element

Arguments

NameType
targetqueue

Returns

element

Description

Removes AND returns the item at the FRONT of target - the one pushed longest ago. Everything behind it moves one place closer to the front.

If target is already empty, nothing is removed and a plain default value is returned instead (0/0.0/false/an empty string/nothing, depending on target's element type) - target never crashes. Check queue_empty(target) first if the game needs to tell "the front really was this value" apart from "target was empty."

Example

/// @type {queue<int>}
/// @capacity 4
var turn_order = [1, 2, 3];
var next_up = queue_pop(turn_order); // 1 - turn_order is now [2, 3]
A real capture - the queue with all three turns still in it, before the popA real capture - the queue with all three turns still in it, before the pop
A real capture - the queue with all three turns still in it, before the pop
The same queue after queue_pop(turn_order) - 1 came off the FRONT, 2 and 3 shifted upThe same queue after queue_pop(turn_order) - 1 came off the FRONT, 2 and 3 shifted up
The same queue after queuepop(turnorder) - 1 came off the FRONT, 2 and 3 shifted up

On the GBA

the GBA module's own deque front()+pop_front() - O(1) (unlike list_remove(target, 0) on a list<T>, which is O(n) - this is queue<T>'s entire reason to exist over list<T>), and the empty case is checked before either is called. The default-value fallback is the same small compiled-in lambda stack_pop uses.

See also: queue_pushqueue_peekqueue_lengthqueue_emptyData containers